package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.pojo.domain.TraceHistory;
import com.ruoyi.system.service.ITraceHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 追踪记录Controller
 * 
 * @author sxb
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/traceHistory")
public class TraceHistoryController extends BaseController
{
    @Autowired
    private ITraceHistoryService traceHistoryService;

    /**
     * 查询追踪记录列表
     */
    @RequiresPermissions("system:traceHistory:list")
    @GetMapping("/list")
    public TableDataInfo list(TraceHistory traceHistory)
    {
        startPage();
        List<TraceHistory> list = traceHistoryService.selectTraceHistoryList(traceHistory);
        return getDataTable(list);
    }

    /**
     * 导出追踪记录列表
     */
    @RequiresPermissions("system:traceHistory:export")
    @Log(title = "追踪记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TraceHistory traceHistory)
    {
        List<TraceHistory> list = traceHistoryService.selectTraceHistoryList(traceHistory);
        ExcelUtil<TraceHistory> util = new ExcelUtil<TraceHistory>(TraceHistory.class);
        util.exportExcel(response, list, "追踪记录数据");
    }

    /**
     * 获取追踪记录详细信息
     */
    @RequiresPermissions("system:traceHistory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(traceHistoryService.selectTraceHistoryById(id));
    }

    @GetMapping(value = "/list/{studentId}")
    public AjaxResult selectTraceHistoryByStudentId(@PathVariable("studentId") String studentId)
    {
        return success(traceHistoryService.selectTraceHistoryByStudentId(studentId));
    }

    /**
     * 新增追踪记录
     */
    @RequiresPermissions("system:traceHistory:add")
    @Log(title = "追踪记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TraceHistory traceHistory)
    {
        return toAjax(traceHistoryService.insertTraceHistory(traceHistory));
    }

    /**
     * 修改追踪记录
     */
    @RequiresPermissions("system:traceHistory:edit")
    @Log(title = "追踪记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TraceHistory traceHistory)
    {
        return toAjax(traceHistoryService.updateTraceHistory(traceHistory));
    }

    /**
     * 删除追踪记录
     */
    @RequiresPermissions("system:traceHistory:remove")
    @Log(title = "追踪记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(traceHistoryService.deleteTraceHistoryByIds(ids));
    }
}
